package com.wfcm.interceptor;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.wfcm.utils.util.ValidateUtil;
@Component
public class LogShowParamInterceptor extends HandlerInterceptorAdapter{
	private Logger log = LoggerFactory.getLogger(LogShowParamInterceptor.class);
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		HandlerMethod method = null;
		if (handler instanceof HandlerMethod) {
			method = (HandlerMethod)handler;
		}
		if(method != null){
			Object bean = method.getBean();
			/*log.debug("requestUrl:"+request.getRequestURI());*/
			/*Map<String, String[]> parameterMap = request.getParameterMap();
			if (ValidateUtil.isValid(parameterMap)) {
				Set<Entry<String,String[]>> entrySet = parameterMap.entrySet();
				for (Entry<String, String[]> entry : entrySet) {
					String[] value = entry.getValue();
					if (ValidateUtil.isValid(value)) {
						if (value.length==1) {
							log.debug("params:"+entry.getKey()+"="+value[0]);
						}else{
							log.debug("params:"+entry.getKey()+"="+Arrays.toString(value));
						}
					}
				}
			}*/
			
		}
		
		return true;
	}
	public static void main(String[] args) {
		/*Integer[] s = {1,2,3};
		System.out.println(Arrays.toString(s));*/
		//int i = test() ;//测试时间比对
		getTimeByDate();
		//System.out.println(i);
		
	}
	
	 public static void getTimeByDate(){
        Date date = new Date();
        DateFormat df1 = DateFormat.getDateInstance();//日期格式，精确到日
        System.out.println(df1.format(date));
        DateFormat sdf = new SimpleDateFormat("yyMMddhhmmssSSS");
        int i = (int)(Math.random() * 1000000);
        String dateString = sdf.format(new Date()) + String.valueOf(i); 
       // DateFormat df2 = sd.getDateTimeInstance();//可以精确到时分秒
        System.out.println(dateString);
        DateFormat df3 = DateFormat.getTimeInstance();//只显示出时分秒
        System.out.println(df3.format(date));
        DateFormat df4 = DateFormat.getDateTimeInstance(DateFormat.FULL,DateFormat.FULL); //显示日期，周，上下午，时间（精确到秒）
        System.out.println(df4.format(date)); 
        DateFormat df5 = DateFormat.getDateTimeInstance(DateFormat.LONG,DateFormat.LONG); //显示日期,上下午，时间（精确到秒）
        System.out.println(df5.format(date));
        DateFormat df6 = DateFormat.getDateTimeInstance(DateFormat.SHORT,DateFormat.SHORT); //显示日期，上下午,时间（精确到分）
        System.out.println(df6.format(date));
        DateFormat df7 = DateFormat.getDateTimeInstance(DateFormat.MEDIUM,DateFormat.MEDIUM); //显示日期，时间（精确到分）
        System.out.println(df7.format(date));
    }
    public void getTimeByCalendar(){
        Calendar cal = Calendar.getInstance();
        int year = cal.get(Calendar.YEAR);//获取年份
        int month=cal.get(Calendar.MONTH);//获取月份
        int day=cal.get(Calendar.DATE);//获取日
        int hour=cal.get(Calendar.HOUR);//小时
        int minute=cal.get(Calendar.MINUTE);//分           
        int second=cal.get(Calendar.SECOND);//秒
        int WeekOfYear = cal.get(Calendar.DAY_OF_WEEK);//一周的第几天
        System.out.println("现在的时间是：公元"+year+"年"+month+"月"+day+"日      "+hour+"时"+minute+"分"+second+"秒       星期"+WeekOfYear);
    }
	
	public static int test()  {
		String DateStr = "2018-3-12 17:20:35";
		DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date orderDate = new Date();
		try {
			orderDate = dateFormat.parse(DateStr);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		long curren = System.currentTimeMillis();
	    curren -= 60 * 60 * 1000;//系统当前时间减一个小时
	    Date date = new Date(curren);
	    int i = orderDate.compareTo(date);
	    
	    return i;
	}
	
}
